//
//  YHHoemAgentMakeCashBackCell.m
//  YHApp
//
//  Created by -- on 2021/7/27.
//

#import "HAHoemAgentMakeCashBackCell.h"
#import "HAPolicyActMo.h"
#import "YHHoemAgentMakeCashBackMCell.h"

@interface HAHoemAgentMakeCashBackCell ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation HAHoemAgentMakeCashBackCell

-(void)setItemArray:(NSMutableArray *)itemArray {
    _itemArray = itemArray;
    [self.tableView reloadData];
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _itemArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    HAPolicyActMo *itemMo = _itemArray[indexPath.row];
    return 54 + itemMo.items.count * (54+36);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YHHoemAgentMakeCashBackMCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHHoemAgentMakeCashBackMCellID"];
    if (!cell) {
        cell = [[YHHoemAgentMakeCashBackMCell alloc]initWithStyle:0 reuseIdentifier:@"YHHoemAgentMakeCashBackMCellID"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.isNotEeit = self.isNotEeit;
    cell.model = _itemArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    self.contentView.backgroundColor = [UIColor khaBGColor];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero];
        // 去掉滚动条
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.contentView addSubview:_tableView];
    }
    return _tableView;
}

@end
